/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gamesorter2;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 *
 * @author th3ory
 */
public class GameSorter2 extends Application {
    
    public TheSorter sorter;
    
    @Override
    public void start(Stage primaryStage) {
        sorter = new TheSorter();
        BorderPane bp = new BorderPane();
        final ListView<String> listView = new ListView<String>();
        listView.setItems(FXCollections.<String>observableArrayList(
                "Zombies!!!", "Carcasonne", "Android: Netrunner", "Forbidden Island"
        ));
        bp.setRight(listView);
        final TextField text = new TextField("");
        text.setMaxSize(140, 20);

        Button btnAdd = new Button();
        btnAdd.setText("Add a Game");
        btnAdd.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                listView.getItems().add(text.getText());
            }
        });
        
        Button btnRank = new Button();
        btnRank.setText("Rank 'Em");
        btnRank.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                sorter.setGames(listView.getItems());
                sorter.startSorting();
            }
        });
        
        bp.setBottom(btnRank);
        
        HBox hbox = new HBox(5);
        hbox.getChildren().addAll(text,btnAdd);
        hbox.setAlignment(Pos.CENTER);
        bp.setLeft(hbox);
        StackPane root = new StackPane();
        root.getChildren().addAll(bp);
        
        Scene scene = new Scene(root, 500, 250);
        
        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * The main() method is ignored in correctly deployed JavaFX application.
     * main() serves only as fallback in case the application can not be
     * launched through deployment artifacts, e.g., in IDEs with limited FX
     * support. NetBeans ignores main().
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}
